package com.eazy.lkv2.web.service.system.count.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.eazy.lkv2.web.entity.LoginLog;
import com.eazy.lkv2.web.service.system.count.BaiduService;
import com.rework.joss.persistence.convention.BaseDao;

@Service
public class BaiduServiceImpl extends BaseDao<LoginLog, String> implements BaiduService {

	@Override
	public List<Map<String, Object>> cityCount() {
		return sqlSessionTemplate.selectList(getMapperMethodId("cityCount"));
	}

	@Override
	public List<Map<String, Object>> areaCount() {
		return sqlSessionTemplate.selectList(getMapperMethodId("areaCount"));
	}

	@Override
	public List<Map<String, Object>> baiduLog() {
		return sqlSessionTemplate.selectList(getMapperMethodId("baiduLog"));
	}

	@Override
	public void createBaiduLog(LoginLog log) {
		sqlSessionTemplate.selectList(getMapperMethodId("baiduLog"), log);
	}

	@Override
	public List<Map<String, Double>> getLocationsBiz(List<LoginLog> result) {
		List<Map<String, Double>> mapList = new ArrayList<>();
		for (LoginLog loginLog : result) {
			if (loginLog.getPointX() != null && loginLog.getPointY() != null) {
				BigDecimal pointX = new BigDecimal(loginLog.getPointX().toString());
				BigDecimal pointY = new BigDecimal(loginLog.getPointY().toString());
				if (pointX != null && pointY != null) {
					Map<String, Double> map = new HashMap<>();
					map.put("x", pointX.doubleValue());
					map.put("y", pointY.doubleValue());
					mapList.add(map);
				}
			}
		}
		return mapList;
	}

}
